/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description:
 * Author: g00421808
 * Create: 6/24/2022
 * Notes:
 */

#ifndef JSBIND_VALUE_TRAIT_H
#define JSBIND_VALUE_TRAIT_H

#include "value.h"

namespace Jsb {

/**
 * @brief: Value对象转型模板
 */
template<typename T>
struct ValueTrait {
    static T Cast(Value& value) {
        return static_cast<T&>(value);
    }
};

// int 手动特化
template<>
struct ValueTrait<int> {
    static int Cast(Value& value) {
        return static_cast<int>(value);
    }
};

// double 手动特化
template<>
struct ValueTrait<double> {
    static double Cast(Value& value) {
        return static_cast<double>(value);
    }
};

// string 手动特化
template<>
struct ValueTrait<std::string> {
    static std::string Cast(Value& value) {
        return value.operator std::string();
    }
};

template<typename T>
struct ValueDefiner {
    typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type RawType;
};

template<typename T>
struct ValueMaker : public ValueDefiner<T>::Type {
    ValueMaker() = default;
    ValueMaker(T t) : ValueDefiner<T>::Type(std::forward<T>(t)) {}
};

} // namespace Jsb
#endif //JSBIND_VALUE_TRAIT_H
